package com.wx.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;


@Service
public class SleuthService {

    private static final Logger logger = LoggerFactory.getLogger(SleuthService.class);

    public void doSomeWorkSameSpan() {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("Doing some work");
    }

    @Async
    public void asyncMethod() {
        logger.info("Start Async Method");
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("End Async Method");
    }

    @Async
    public CompletableFuture<String> sendUser(String user) {
        logger.info("enter sendUser:" + user);
        try {
            Thread.sleep(3000L);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user = user + "complete";
        logger.info("sendUser:" + user);
        return CompletableFuture.completedFuture(user);
    }
}
